QCustomPlot 启用 OpenGL

编译时添加预编译宏 QCUSTOMPLOT_USE_OPENGL,用绘图的 QCustomPlot 子类调用 setOpenGl(true),并链接 OpenGL32

在 Windows 上使用 OpenGL32 存在很严重的性能问题,可以改为使用 freeglut

图像错乱问题

修改 QCPPaintBufferGlFbo::draw,添加上下文切换的代码。

1void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const
2{
3  if (!painter || !painter->isActive())
4  {
5    qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed";
6    return;
7  }
8  if (!mGlFrameBuffer)
9  {
10    qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
11    return;
12  }
13  
14  // 添加
15  if (QOpenGLContext::currentContext() != mGlContext.data()) {
16    mGlContext.data()->makeCurrent(mGlContext.data()->surface());
17  }
18  
19  painter->drawImage(0, 0, mGlFrameBuffer->toImage());
20}